<script>
    var arr = ['鹿晗', '王俊凯', '蔡徐坤', '彭于晏', '周杰伦', '刘德华', '赵本山']
    var ar = new Array
    for (i = 0; i < 4; i++) {
        while (true) {
            l = false
            do {
                r = Math.floor(Math.random() * 10)
            } while (r >= arr.length)//随机取一个arr内的下标

            ar[i] = arr[r]
            for (ii = i - 1; !(ii < 0); ii--) {
                if (ar[i] == ar[ii]) {
                    l = true
                    break
                }
            }//检查到重复就重新取一个
            if (l)
                continue
            break
        }
    }
    alert(ar)
</script>